;================
;Kyle Kelly
;CS2110-B2
;Lab12 Wimpy
;===============

.orig x3000
LD R6, STACK_INIT
LD R5, STACK_INIT

ADDR0R1
	ADD R6, R6, -3	;SP+3
	STR R7, R6, 2	;STORE OLD RET ADDR
	STR R5, R6, 1	;STORE OLD FP
	LDR R5, R6, 0	;SET NEW FP
	STR R0, R5, 0	;STORE OLD R0
	STR R1, R5, -1	;STORE OLD R1
	ADD R6, R6, -1	;SP+1
	
	ADD R0, R1, 0;
	BRZ BZERO
	ADD R1, R1, -1	;DECREMENT R1
	LDR R0, R5, 0	;RESTORE R0
	JSR ADDR0R1		;ADDR0R1 (A, B-1)
	ADD R0, R0, 1	;R0 ++
	BRNZP DONE
	BZERO
	LDR R0, R5, 0	;DONE SO RETURN A INSTEAD
	DONE
	LDR R1, R5, -1	;RESTORE OLD R1
	ADD R6, R5, 0	;MOVE SP TO CURRENT FP
	LDR R7, R5, #2	;RESTORE RET ADDR
	LDR R5, R5, #1	;RESTORE OLD FP
	ADD R6, R6, #3	;MOVE SP TO ARG1
	RET
	
	
	
;**********Variables************

STACK_INIT .fill xF000
